package dom.util;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;

public class Connections {
	public static Connection getConnection(){
		 String url1 ="jdbc:mysql://127.0.0.1:3306/RedWine";
	     String userName="root";
	     String passw="lxy1124";
	     String url2 ="?user="+userName+"&password="+passw;
	     String  url3="&useUnicode=true&characterEncoding=UTF-8";
	     String url =url1+url2+url3;
	     java.sql.Connection connection=null;
	     try {
		     Class.forName("com.mysql.jdbc.Driver");
			 connection=DriverManager.getConnection(url);
			 return (Connection) connection;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
    public static void closeDB(Connection con,PreparedStatement  pstm, ResultSet rs){
  	   try{
  		   if(rs!=null) rs.close(); 
  		   if(pstm!=null) pstm.close();
 		   if(con!=null) con.close();				 
 	   }catch (SQLException e) {				
 			e.printStackTrace();			
 	   }
 	}
}
